# -*- mode: python; -*-

#
# Copyright (c) 2018 Juniper Networks, Inc. All rights reserved.
#
# Placeholder for fabric-ansible Sconscript

import os

Import('CfgmEnv')
env = CfgmEnv.Clone()

setup_sources = [
           'setup.py',
           'MANIFEST.in',
           'run_tests.sh',
           'requirements.txt',
           'test-requirements.txt',
           'test',
           'conf',
           'group_vars',
           'library',
           'module_utils',
           'roles',
           'schema',
           'filter_plugins',
           'templates',
           'common',
          ]

setup_sources_rules = []
for file in setup_sources:
    setup_sources_rules.append(
        env.Install(Dir('.'), "#controller/src/config/fabric-ansible/ansible-playbooks/" + file))

local_sources = [
    'assign_static_device_ip.yml',
    'delete_fabric.yml',
    'delete_fabric_devices.yml',
    'device_import.yml',
    'discover_device.yml',
    'image_upgrade.yml',
    'hitless_upgrade.yml',
    'fabric_onboard.yml',
    'existing_fabric_onboard.yml',
    'error_handler.yml',
    'discover_role.yml',
    'topology_discovery.yml',
    'hitless_upgrade_strategy.yml',
    'ansible.cfg',
    'postscript.yml',
    'ztp.yml',
    'fabric_config.yml',
    'feature_config.yml',
    'role_assignment.yml',
    'percentage_update.yml',
    'operational_command.yml',
    'discover_server.yml',
    'ipmi_discovery.yml',
    'node_profile.yml',
    'plugin_ironic.yml',
    'server_import.yml',
    'hitless_upgrade_errors.yml',
    'update_dhcp_config.yml',
]

local_sources_rules = []
for file in local_sources:
    local_sources_rules.append(
        env.Install(".",
                    "#controller/src/config/fabric-ansible/ansible-playbooks/" + file))

cd_cmd = 'cd ' + Dir('.').path + ' && '
sdist_depends = []
sdist_depends.extend(setup_sources_rules)
sdist_depends.extend(local_sources_rules)
sdist_gen = env.Command('dist/fabric_ansible_playbooks-0.1dev.tar.gz', 'setup.py', cd_cmd + 'python setup.py sdist')

env.Depends(sdist_gen, sdist_depends)
env.Default(sdist_gen)

install_cmd = env.Install(env['INSTALL_BIN'],
   "#controller/../build/" + env['OPT'] + "/config/fabric-ansible/ansible-playbooks/dist/fabric_ansible_playbooks-0.1dev.tar.gz")

env.Alias('install', install_cmd)
env.Depends(install_cmd, sdist_gen)

